﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using IcbcOpenDemo.Models.Tools;
namespace IcbcOpenDemo.Models
{
    #region Request
    class MybankEnterpriseAccountQaccbalRequestV1 : AbstractIcbcRequest<MybankEnterpriseAccountQaccbalResponseV1>
    {
        /// <summary>
        /// 获取响应类
        /// </summary>
        /// <returns>返回SettlementAccountBalanceQueryRequestV1类对应的响应类类型</returns>
        public override Type getResponseClass()
        {
            return Type.GetType("sdk_cop.MybankEnterpriseAccountQaccbalResponseV1");
        }

        /// <summary>
        /// SettlementAccountBalanceQueryRequestV1类的构造函数，设置请求URL
        /// </summary>
        public MybankEnterpriseAccountQaccbalRequestV1()
        {
            this.setServiceUrl("https://apipcs3.dccnet.com.cn/api/mybank/enterprise/account/qaccbal/V1");
            //this.setServiceUrl("https://apipcs3.dccnet.com.cn/api/mybank/pay/cpay/cporderquery/V2");            
        }

        /// <summary>
        /// 是否支持加密（目前sdk只支持对字段进行AES加解密）
        /// </summary>
        /// <returns>一般返回false</returns>
        public override Boolean isNeedEncrypt()
        {
            return false;
        }
        /// <summary>
        /// http发起请求方式（支持GET、POST两种方式）
        /// </summary>
        /// <returns>一般返回POST</returns>
        public override String getMethod()
        {
            return "POST";
        }

        /// <summary>
        /// 获取业务类类型
        /// </summary>
        /// <returns>返回request类内部定义的BizContent类的类型</returns>
        public override Type getBizContentClass()
        {
            return Type.GetType("sdk_cop" + ".MybankEnterpriseAccountQaccbalRequestV1+MybankEnterpriseAccountQaccbalRequestV1Biz", true, true);

        }

        #region bizcontent内容
        /// <summary>
        /// 内部业务类，封装需要发送给服务端的业务字段
        /// </summary>
        [DataContract]
        public class MybankEnterpriseAccountQaccbalRequestV1Biz : BizContent
        {
            [DataMember]
            public String trans_code;
            [DataMember]
            public String cis;
            [DataMember]
            public String bank_code;
            [DataMember]
            public String login_id;
            [DataMember]
            public String tran_date;
            [DataMember]
            public String f_seq_no;
            [DataMember]
            public String language;
            [DataMember]
            public string tran_time;
            [DataMember]
            public int total_num;
            [DataMember]
            public List<RequestRd> rd;
        }

        public class RequestRd
        {
            public string i_seq_no;

            public string account_no;

            public string currency;

            public string sub_no;

            public string bank_type;
        }
        #endregion
    }

    #endregion

    #region Response
    [Serializable]
    [DataContract]
    class MybankEnterpriseAccountQaccbalResponseV1 : IcbcResponse
    {
        [DataMember]
        public string trans_code { get; set; }

        [DataMember]
        public string cis { get; set; }

        [DataMember]
        public string bank_code { get; set; }

        [DataMember]
        public string login_id { get; set; }

        [DataMember]
        public string tran_date { get; set; }

        [DataMember]
        public string tran_time { get; set; }

        [DataMember]
        public string f_seq_no { get; set; }

        [DataMember]
        public List<ResponseRd> rd { get; set; }
    }

    public class ResponseRd
    {
        public string i_seq_no { get; set; }
        public string account_no { get; set; }
        public string currency { get; set; }
        public int cash_exf { get; set; }
        public int account_property { get; set; }
        public int yesterday_balance { get; set; }
        public int balance { get; set; }
        public int usable_balance { get; set; }
        public int frozen_amt { get; set; }
        public string query_time { get; set; }
        public string i_ret_code { get; set; }
        public string i_ret_msg { get; set; }
        public string bank_type { get; set; }
        public string account_name { get; set; }
        public int hold_amt { get; set; }
        public string last_intr_date { get; set; }
        public string sub_no { get; set; }
        public string last_tran_date { get; set; }
    }
    #endregion

    class MybankEnterpriseAccountQaccbalV1Test
    {
        ///APP_ID：通过内管查看详情，可获取对应的组织机构、接入方式、公钥等信息；APP管理中查看
        ///MY_PRIVATE_KEY:RSA私钥，可以通过sdk包下面bin文件夹里面的工具生成一对公私钥
        ///APIGW_PUBLIC_KEY:网关公钥
        protected static string APP_ID = "10000000000000237521"; 
        //protected static String APP_ID = "10000000000000187514";
        //protected static String APP_ID = "10000000000000189505";
        
        //protected static String MY_PRIVATE_KEY = @"MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCvdD1ku0eCB8ABMY+FBAbqCbJ/KM4VNMIs5QAY5skDYisoqOs7PJKk3b6MahoDjYe3wbzStV1yAO9VUHAccxyxEc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8SeCIOwAw80f4TMuJf7NMEVIxCBiiC8MWX327Y62aYFB7Sz+Ds1PjxjdraFw/LKRRS74E1DKitrplaBnBicXJLv9CsQKBgQDocKkOTeKuI9aCo59JzBY5U70xojdLbCXcwE64S77p3TlqKYiK1NkzXxROXunmxih12tQTfwuDcID8twFMOCUdGrk41sGTReK6wiXXXVFWUtcD3+z1VeoztCat67PXNH3dGn32ON3Q47FGdN5uPE8bSd8cLDzYmFbP8Huf0VToPQKBgQCop/rFOzMdg95byCfu32B4bZRXNEHS8kJ/izns7Dxh4dLMRTGaHbNNa82duXQYpdUHTNmAB7ZU1flWbkVTEIzK2AWEiIxv6P0+1bObVHT/E0aAX6PuREEtqSO2SJmblae/W1WXKKfzN2gwibVlUX7DR7oI/fxbP1kBHnnOn0KQVQKBgQCTRB239Fy0G/yilGwtY2KJO6bYtX/3BzQN4sF9PnBc106zFlFuNGDQjWLeLIBhOBcWZGiNWaa/xh3S/1eRJNlO0Umc22OVnWeDD9LN2k/YM3ALAmqtHZve2jrPYlB0/srntQstXuYanMgKba0nhopQLcNvpA+A4zPNVv3cSdJTuQKBgQCNWrzDMarVwgBLzKYrfuzMAouhyxqgQouZeodCG31ATJTwv82i7eGpsgDTgOvc/KBfTfm9ZLlcwToJRsKzq9tU51k4i3mpEg2u7E1skoy8fNtKHN64hFxceLaFwLN9wyClMVe7KUgagQXCKKjwEi28XhF+F+G6WI2wcmqE0tZnQQKBgBi7AcXC7fUAK8Gm5Yzzd0oszIjx9RmfS0W0Y+ngHeO06xFwikctOdXJw9HwyGeWEqnCLYehclZZykYpD7jRgiF7XHK4XV8sK0G9CFTTyHQ0Xx9zrr5JvgaJxZ0l4IFovnAbWZsvkSBt0g0yTpniebLdPSZfqKWUZZFed2ahlLko";
        
        protected static String APIGW_PUBLIC_KEY = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmSJ0IMT8AWzkJJd7LbZNQS4kTXes7iy5mJMUwogIlhxzegvxXEF9lHbgli9vAQQqUVy64nFeOH6drO+db9e3vZPSND3ATeh7MedahUDVcEKFMHBbffn8f+0raf+zNKY/+wriWHhXrDpGdcKN4Ujlpc1eRkgOLjTBvtcuhNg9igc4+IG9i6QWTtRecvwzDru8HW0gEhG6CX/VXzSlMQWuBfG9hlY/1whX3Y843f8nU4ffUqOBUVbappEut52FK1TD9pj/an/2r9D+rjE+d9WTs5FJCp22lMud9lyU/g0+bmGIXCFMIca/Ntz32atCCH2MN8sZVJr8BC562FwIBo1sQQIDAQAB";

        public static void test()
        {
            /// <summary>
            /// 非页面服务实现类(RSA加解密方式) 
            /// </summary>
            /// <param name="APP_ID">应用id</param>
            /// <param name="MY_PRIVATE_KEY">RSA私钥</param>
            /// <param name="APIGW_PUBLIC_KEY">网关公钥</param>
            /// <returns>非页面服务实现类实例</returns>
            DefaultIcbcClient client = new DefaultIcbcClient(APP_ID, IcbcConstants.SIGN_TYPE_RSA2, MY_PRIVATE_KEY, APIGW_PUBLIC_KEY);
            ///新建服务请求类实例
            MybankEnterpriseAccountQaccbalRequestV1 request = new MybankEnterpriseAccountQaccbalRequestV1();
            ///新建服务请求类的业务参数类，该类为内部类
            MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestV1Biz bizContent = new MybankEnterpriseAccountQaccbalRequestV1.MybankEnterpriseAccountQaccbalRequestV1Biz();
            ///为请求类设置各种参数
            request.setServiceUrl("https://apipcs4.dccnet.com.cn/api/mybank/enterprise/account/qaccbal/V1");            

            bizContent.trans_code = "QACCBAL";
            //bizContent.cis = "201190001614002";
            bizContent.cis = "201190000676644";
            bizContent.bank_code = "102";
            bizContent.login_id = "lanjuapics4.y.2011";
            bizContent.tran_date = SeqNo.TranDate;
            bizContent.f_seq_no = SeqNo.FSeqNo;
            bizContent.language = "zh_CN";
            bizContent.tran_time = SeqNo.TranTime;
            bizContent.total_num = 1;
            bizContent.rd = new List<IcbcOpenDemo.Models.MybankEnterpriseAccountQaccbalRequestV1.RequestRd>
            {
                //new IcbcOpenDemo.Models.MybankEnterpriseAccountQaccbalRequestV1.RequestRd{i_seq_no="1",account_no="2011027819200038020",currency="CNY",sub_no="",bank_type="102"}
                //new IcbcOpenDemo.Models.MybankEnterpriseAccountQaccbalRequestV1.RequestRd{i_seq_no="1",account_no="2011021709024202606",currency="CNY",sub_no="",bank_type="102"}                
                new IcbcOpenDemo.Models.MybankEnterpriseAccountQaccbalRequestV1.RequestRd{i_seq_no="1",account_no="2011002219248101818",currency="CNY",sub_no="",bank_type="102"}
            };

            request.setBizContent(bizContent);

            //同步调用并返回response响应类
            MybankEnterpriseAccountQaccbalResponseV1 response = null;
            try
            {
                response = (MybankEnterpriseAccountQaccbalResponseV1)client.execute(request, SeqNo.Msg_ID);
            }
            catch (System.Net.WebException e) //无法连接到远程服务器，网络异常
            {
                throw e;
            }
            catch (Exception ex)//抛出其他异常
            {
                throw ex;
            }
            //获取响应类的返回代码，小于0表示业务失败，等于0表示调用成功，大于0表示系统失败
            if (response.getReturnCode() < 0)
            {
                Console.WriteLine("业务失败!");
            }
            else if (response.getReturnCode() == 0)
            {
                Console.WriteLine("成功!");
            }
            else
            {
                Console.WriteLine("系统失败!");
            }

        }
    }
}
